var app = new Vue({
    el:".form-horizontal",
    data:{
        // 页面中需要使用到的数据，键值对
        HOST,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,

        title:'',
        tag:'',
        concent:'',
        category:'',
        categories:'',

    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        axios.get(this.HOST + 'newcategories')
            .then(response => {

                this.categories = response.data.results;
                console.log(this.categories);
            });

    },
    methods:{
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
        get_news:function(){
            // alert(1)
            this.concent = CKEDITOR.instances.editor1.getData();
            axios.post(this.HOST + 'newssubmit/',
                        {
                            title:this.title,
                            tag:this.tag,
                            concent:this.concent,
                            category:this.category,
                        },
                        {
                            headers: {
                                'Authorization': 'JWT ' + this.token
                            },
                        })
                        .then(response => {
                            location.href = '/headline-logined.html';
                        }

                    )
        },


    },
});
